<?php

require_once( $CFG->dirroot . 'mod/folio/model/file.php');

class folio_FileImage {

    /**
     * Return a filepath representing the extension of the passed file
     *
     * @return string Fully-qualified url
     */
    public function html( $file )  {
        global $CFG;

        // Check for error on file
        if( $file == false ) {
            return $CFG->wwwroot . 'mod/folio/image/file_missing.png';
        }

        // Default Entry when no file
        if( $file == null )
            return $CFG->wwwroot . 'mod/folio/image/mime/other.png';

        if( strlen($file->originalname) > 4 ) {
            $ext = substr( $file->originalname, strlen($file->originalname)-3 );
            $images = array('avi','doc','ocx','exe','gif','.gz','jpg','jpeg','mov','mp3','mp4',
                            'pdf','png','ppt','ptx','rtf','tar','txt','wav','xls','lsx','zip');

            if( array_search( $ext, $images ) ) {
                return $CFG->wwwroot . "mod/folio/image/mime/{$ext}.png";
            }
        }
        return $CFG->wwwroot . 'mod/folio/image/mime/other.png';
    }
}
?>
